package main;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author daz
 */
public class Request {

    private static DataTransfer dataTransfer;

    public static void initializeConnection() {
        dataTransfer = DataTransfer.getInstance();
    }

    public static void setMessageListenner(IMessageListenner messageListenner) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.setMessageListenner(messageListenner);
    }

    public static void chosseGame(int gameType) {
        Debug.d("request choosse game:" + dataTransfer);
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("GA|" + gameType);
    }

    public static void login(String userName, String password) {
        if (dataTransfer == null) {
            return;
        }
        String platform = System.getProperty("microedition.platform");
        String[] device = StringHelper.split(platform, '/');
        if (device != null) {
            dataTransfer.request("FIFTH_LO|" + userName + "|" + password + "|" + Constants.VERSION + "|" + device[0]);
        } else {
            dataTransfer.request("FIFTH_LO|" + userName + "|" + password + "|" + Constants.VERSION + "|J2ME");
        }
    }

    public static void fnMessgePhom() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("FN|");
    }

    public static void finishPhom(int[] cardIds, int numberCard) {
        if (dataTransfer == null) {
            return;
        }
        StringBuffer msg = new StringBuffer();
        msg.append("SCO");
        msg.append("|");
        for (int i = 0; i < numberCard; i++) {
            msg.append(cardIds[i]);
            if (i != numberCard - 1) {
                msg.append("|");
            }
        }
        dataTransfer.request(msg.toString());
    }

    public static void register(String userName, String password, int gender, int companyId) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("REGISTER|" + userName + "|" + password + "|" + gender + "|" + Constants.VERSION + "|" + companyId);
    }

    public static void responseFriendRequest(int result) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RMF|" + result);
    }

    public static boolean isConnect() {
        if (dataTransfer == null) {
            return false;
        }
        return dataTransfer.isConnect();
    }

    public static void eatCardPhom(int playeEatId, int cardId, int anChot) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("EA|" + playeEatId + "|" + cardId + "|" + anChot);
    }

    public static void haphom(int playerId, int[] phom, int phomLength) {
        if (dataTransfer == null) {
            return;
        }
        StringBuffer msg = new StringBuffer();
        msg.append("HP|");
        msg.append(playerId);
        msg.append("|");
        for (int i = 0; i < phomLength; i++) {
            msg.append(phom[i]);
            if (i != phomLength - 1) {
                msg.append("|");
            }
        }
        dataTransfer.request(msg.toString());
    }

    public static void finishBacay() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CT|");
    }

    public static void changeGameRule(int rule) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("GM|" + rule);
    }

    public static void changeReadyState(int state) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RE|" + state);
    }

    public static void winUPhom(int type) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("U|" + type);
    }

    public static void getCardDraw() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("NB|");
    }

    public static void finishTienlen() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CT|");
    }

    public static void finishPhom(int idWind) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CT|" + idWind);
    }

    public static void exitChooseRoom() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RGA|");
    }

    public static void exitTable() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RRO|");
    }

    public static void exitChoooseTable() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RSE|");
    }

    public static void finishGame(int turn) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("FINISH|" + turn);
    }

    public static void joinGame(String name) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("JOIN|" + name);

    }

    public static void checkMate(int id) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CHECKMATE|" + id + "|" + (1 - id));;
    }

    public static void movePiece(int id, int srcRow, int srcColumn, int desRow, int desColumn) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("STEP|" + id + "|" + srcRow + "|" + srcColumn + "|" + desRow + "|" + desColumn);
    }

    public static void enterRoom(int roomId) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("SE|" + roomId);
    }

    public static void enterTable(int tableId) {
        if (dataTransfer == null) {
            return;
        }
        Debug.d("table choose :" + tableId);
        dataTransfer.request("RO|" + tableId);
    }

//    public static void exitServer() {
//        if (dataTransfer == null) {
//            return;
//        }
//        dataTransfer.request("Q");
//    }
    public static void fightCardPhom(int playerId, int cardId) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("DB|" + playerId + "|" + cardId);
    }

    public static void finishOpenCardBaCay() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("FN|");
    }

    public static void fightCardTienlen(int playerId, int lastplayerFightId, int blockCardType, int[] fightCardArr) {
        if (dataTransfer == null) {
            return;
        }
        StringBuffer msg = new StringBuffer();
        msg.append("DB2|");
        msg.append(playerId);
        msg.append("|");
        msg.append(lastplayerFightId);
        msg.append("|");
        msg.append(blockCardType);
        msg.append("|");
        for (int i = 0, l = fightCardArr.length; i < l; i++) {
            msg.append(fightCardArr[i]);
            if (i != l - 1) {
                msg.append("|");
            }
        }
        Debug.d("msg :" + msg.toString());
        dataTransfer.request(msg.toString());
    }

    public static void skipTurnTienlen(int id) {
        dataTransfer.request("BL|" + id);
    }

    public static void tienlenFn2(int gameResult, int numberPlayerStart, int playerId) {
        dataTransfer.request("FN2|" + gameResult + "|" + numberPlayerStart + "|" + playerId);
    }

    public static void tienlenFn3(int gameResult, int numberPlayerStart, int playerId) {
        dataTransfer.request("FN3|" + gameResult + "|" + numberPlayerStart + "|" + playerId);
    }

    public static void finishChessGame(int winID) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CT|" + winID);
    }

    public static void enterBattle(int playerId, int oldRowKing, int oldColumKing, int newRowKing,
            int newColumnKing, int oldRowRock, int oldColumnRock, int newRowRock, int newColumRock) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("EB|" + playerId + "|" + oldRowKing + "|" + oldColumKing + "|" + newRowKing + "|"
                + newColumnKing + "|" + oldRowRock + "|" + oldColumnRock + "|" + newRowRock + "|" + newColumRock);
    }

    public static void betMoney(String moneyBet) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("MS|" + moneyBet);
    }

    public static void askForDraw(int id) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("DRAW|" + id);
    }

    public static void acceptLose(int id) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("LOSE|" + id);
    }

    public static void doneTienlen(int id) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("LOSE|" + id);
    }

    public static void promoteChess(int chessId, int row, int column) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("UPG|" + chessId + "|" + row + "|" + column);
    }

    public static void kickOut(String userName) {
        Debug.d("kick :" + userName);
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("KICK|" + userName);
    }

    public static void chat(String message) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CHAT|" + message);
    }

    public static void nextTurnChess() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("NEXT|");
    }

    public static void reponseDrawAsk(int result) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("AD|" + result);
    }

    public static void sendFriendRequest(String sender, String receiver) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("MF|" + sender + "|" + receiver);
    }

    public static void sendDepositCard(int fromId, int toId, int cardId, int posType) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("GUI|" + fromId + "|" + toId + "|" + cardId + "|" + posType);
    }

    public static void sendLuckCoinCredit(String dataCredit) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("XENG|" + dataCredit);
    }

    static void getUserInfo() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("INFO|");
    }

    public static void sendMessage(int kind, String userReceive, String message) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("MSG|" + userReceive + "|" + kind + "|" + message);
    }

    static void getUserInfo(String name) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("INFO|" + name);
    }

    static void getListFriend() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("LF|");
    }

    static void getListItem() {
        Debug.d("get list item :" + dataTransfer);
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("MYI|");
    }

    static void getTopRich() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("TR|");

    }

    static void getTopLevel() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("TL|");

    }

    static void getListMessage() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("LMSG|");

    }

    static void useItem(int itemId) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("API|" + itemId);
    }

    static void buyItem(int itemId) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("BUY|" + itemId + "|" + 1);
    }

    static void birthChild(String matName) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("BIR|" + matName);
    }

    static void nameChild(String childName) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("NAME|" + childName);
    }

    static void readMessage(int indexSelected) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RMSG|" + indexSelected);
    }

    static void deletedMessage(int indexSelected) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("DMSG|" + 1 + "|" + indexSelected);
    }

    static void deletedAllMessage(int number, int[] id) {
        if (dataTransfer == null) {
            return;
        }
        StringBuffer msg = new StringBuffer();
        msg.append("DMSG|").append(number);
        for (int i = 0; i < number; i++) {
            msg.append("|").append(id[i]);
        }
        dataTransfer.request(msg.toString());
    }

    static void setTablePass(String pass) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("PASS|" + pass);
    }

    static void speak(String text) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("SPEAK|" + text);
    }

    static void changePass(String userNameShow, String passwordClear, String newPassClear) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CPASS|" + userNameShow + "|" + passwordClear + "|" + newPassClear);
    }

    static void setupNumberPlayers(int number) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("SU|" + number);
    }

    static void request(String msg) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request(msg);
    }

    static void quit() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("Q|");
    }

    static void setStatus(String text) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("SS|" + text);
    }

    static void ping() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("PING|");
    }

    static void deleteFriend(String myName, String friend) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("DELETEFRIEND|" + myName + "|" + friend);
    }

    static void useCard(String issuerName, String cardCode, String cardSerial) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("USECARD|" + issuerName + "|" + cardCode + "|" + cardSerial);
    }

    static void updateMoney() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("UMO|");
    }

    static void checkSms() {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("CHECKSMS|");
    }

    static void openBaCay(int playerId, int startOpen) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("OB|" + playerId + "|" + startOpen);
    }

    static void resetPass(String userNameShow) {
        if (dataTransfer == null) {
            return;
        }
        dataTransfer.request("RSMK|" + userNameShow);
    }
}
